﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using FineUI;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Data;

namespace IHISCETeim.Web.AgentSys.SvrMgr
{
    public partial class AgentQltyView : AgentPageBase
    {

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get { return "AgentQltyList"; }
        }

        protected int QltyId
        {
            get
            {
                return GetRequestValue<int>("QltyId", 0);
            }
        }
        private AgentQltyInfo _objQlty = null;
        protected AgentQltyInfo objQlty
        {
            get
            {
                if (_objQlty == null)
                {
                    _objQlty = AgentQltyController.GetByQltyId(QltyId);
                }
                return _objQlty;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        private void LoadData()
        {
            btnClose.OnClientClick = GetCloseActiveTabScript(); 
            //检查是否是自已的品情
            if (objQlty.UserId != base.User.UserId)
            {
                Alert.ShowInTop("您只能查看您自已的品情", "警告", MessageBoxIcon.Warning, "top.removeActiveTab()");
                return;
            }
            //
            LoadQltyInfo();
        }

        private void LoadQltyInfo()
        {
            this.ClaimsNumber.Text = objQlty.ClaimsNumber;
            this.IssueDate.Text = objQlty.IssueDate.ToString("yyyy-MM-dd");
            this.AgentName.Text = objQlty.AgentName;
            this.SerialNumber.Text = objQlty.SerialNumber;
            this.MachineType.Text = objQlty.MachineType;
            this.CustomerName.Text = objQlty.CustomerName;
            this.CustomerMobile.Text = objQlty.CustomerMobile;
            this.IntoDate.Text = objQlty.IntoDate.ToString("yyyy-MM-dd");
            this.IntoAddress.Text = objQlty.IntoAddress;
            this.FaultDate.Text = objQlty.FaultDate.ToString("yyyy-MM-dd");
            this.WorkHour.Text = objQlty.WorkHour.ToString("F0");
            this.ReportUser.Text = objQlty.ReportUser;
            this.ReportTel.Text = objQlty.ReportTel;
            this.MacNature.SelectedValue = objQlty.MacNature;
            this.IntoConditi.SelectedValue = objQlty.IntoConditi;
            this.IntoSpecial.SelectedValue = objQlty.IntoSpecial;
            this.DamagePartsNumber.Text = objQlty.DamagePartsNumber;
            this.HEFaultDescription.Text = objQlty.FaultDescription;
            this.HEFaultReason.Text = objQlty.FaultReason;
            this.HEProcessMode.Text = objQlty.ProcessMode;

            this.ReportType.SelectedValue = objQlty.ReportType;
            this.IsVisit.Checked = objQlty.IsVisit;
            this.SvrResult.Text = objQlty.SvrResult;
            this.SvrScheme.Text = objQlty.SvrScheme;
            this.PartsSendDate.SelectedValue = objQlty.PartsSendDate;
            this.PartsSendType.SelectedValue = objQlty.PartsSendType;


            this.ClaimState.Text = objQlty.ClaimState;
            this.CancelReason.Text = objQlty.CancelReason;
            this.IsCancelReason.Checked = objQlty.IsCancelReason;
            this.CancelReason.Readonly = objQlty.IsCancelReason;

            ///加载图片
            List<AgentQltyImgInfo> listImg = AgentQltyController.GetAllImgByQltyId(QltyId);
            for (int imgIndex = 1; imgIndex <= listImg.Count-1; imgIndex++)
            {
                //FineUI.FileUpload FileUpladControl = Panel4.FindControl("filePhoto" + imgIndex) as FineUI.FileUpload;                
                FineUI.Image imgRelativelyControl = Panel4.FindControl("imgRelatively" + imgIndex) as FineUI.Image;
                FineUI.TextBox ImgTitleControl = Panel4.FindControl("ImgTitle" + imgIndex) as FineUI.TextBox;

                ImgTitleControl.Text = listImg[imgIndex - 1].Title;
                imgRelativelyControl.ImageUrl = listImg[imgIndex - 1].IMGRelatively;
            }
            try
            {
                this.fileOtherDownLoad.NavigateUrl = listImg[6].IMGRelatively;
                this.fileOtherDownLoad.Hidden = string.IsNullOrEmpty(listImg[6].IMGRelatively);
            }
            catch { 
            
            }
            //加载配件
            List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            
            this.grdAgentQltyParts.DataSource = listParts;
            this.grdAgentQltyParts.DataBind();

        }        

        protected void grdAgentQltyParts_RowDataBound(object sender, GridRowEventArgs e)
        {
            //AgentQltyPartsInfo itmData = e.DataItem as AgentQltyPartsInfo;
            //System.Web.UI.WebControls.DropDownList ddl = grdAgentQltyParts.Rows[e.RowIndex].FindControl("ddlPartsDemand") as System.Web.UI.WebControls.DropDownList;
            //ddl.SelectedValue = itmData.PartsDemand;

        }
    }
}